package com.sykj.springboot.controller.index;

import com.sykj.springboot.common.Exception.BussinessException;
import com.sykj.springboot.common.Exception.TimeOutException;
import com.sykj.springboot.common.entity.DataResponse;
import com.sykj.springboot.common.utils.RedisUtils;
import com.sykj.springboot.entity.SysUser;
import com.sykj.springboot.service.SysUserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("index")
public class IndexController {

    @Autowired
    SysUserService sysUserService;

    @RequestMapping("/")
    public String index(HttpServletResponse response) {
        return "/index";
    }


    /**
     * @Description:查看用户
     * @Author: lining
     * @Date: 14:46 2022/9/22
     */
    @RequestMapping("getUserInfoByToken")
    public DataResponse getUserInfoByToken(HttpServletRequest request, String token) throws Exception{
        DataResponse response = new DataResponse();
        if (StringUtils.isBlank(token)){
            throw new TimeOutException("登录超时");
        }
        SysUser byId = (SysUser)RedisUtils.getObjFromRedis(token);
        response.setData(byId);
        return response;
    }
}
